/* GSUniteGwProcessor.java
 *
 * Project/Product: GWBS2009
 *
 * Modify Information:
 * =============================================================================
 *   Author	Date       Description
 *   ----------	---------- ---------------------------------------------------
 *   Administrator	2009-3-12	First release
 *
 * Licensed Materials - Property of APEP
 * =============================================================================
 *    (C) COPYRIGHT Shanghai Auto Mart E-Procurement Co., Ltd. 2007 - 2009
 *    All Rights Reserved.
 *
 *    This software is the confidential and proprietary information of
 *    Shanghai Auto Mart E-Procurement Co., Ltd. ("Confidential Information").
 *    You shall not disclose such Confidential Information and shall use it only
 *    in accordance with the terms of the license agreement you entered into 
 *    with Shanghai Auto Mart E-Procurement Co., Ltd.
 *
 * Noties:
 * =============================================================================
 * 
 */

package com.hitrust.gs.business;

import java.util.ArrayList;

import com.hitrust.gs.bean.GSWareHouseBean;
import com.hitrust.gs.dao.GSUniteGwDAO;
import com.hitrust.gs.util.exception.GSException;

import framework.core.ConstDefine;

public class GSUniteGwProcessor {
    private GSUniteGwDAO dao=new GSUniteGwDAO();
    /***
     * 得到自己下属及巴士物资(供采购使用)
     * **/
    public ArrayList getBzwzAndTmpWareHouse(String currentWareCode) throws GSException{
        ArrayList wareList=this.getWareHouseList(currentWareCode);
        GSWareHouseBean tmp= new GSWareHouseBean();
        tmp.setCode(ConstDefine.T_WARE_HOUSE_CODE);//所有正式产品
        tmp.setName(ConstDefine.T_WAREE_HOUSE_NAME);
        wareList.add(tmp);
        return wareList;
    }
    public  GSWareHouseBean getWareHouseByCode(String code) throws GSException{
        return dao.queryWareHouseByCode(code);
    }
    /**
     * 获取自己级下级仓库
     * **/
    public ArrayList getWareHouseList(String currentWareCode) throws GSException{
        ArrayList wareList = dao.queryWareHouse(currentWareCode);
        return wareList;
    }
    /**
     * 获取登录用户权限
     * */
    public ArrayList getUserMenuInfo(String userId) throws GSException{
        ArrayList menuList=dao.queryUserMenuInfo(userId);
        return menuList;
    }
    /**
     * 对仓库名称按级别显示
     * **/
    public ArrayList getWareHouseLevelName(String currentWareCode,String selectCode) throws GSException{
        ArrayList wareList = dao.queryWareHouse(currentWareCode);
        for (int tI = 0; tI < wareList.size(); tI++) {
            GSWareHouseBean tGSWareHouseBean=(GSWareHouseBean) wareList.get(tI);
            tGSWareHouseBean.setName(getWarehouseName(selectCode, tGSWareHouseBean.getCode(), tGSWareHouseBean.getName()+"("+tGSWareHouseBean.getCode()+")"));
        }
        return wareList;
    }
    
    /**
     * 对仓库名称按级别显示
     * (订货单位所属分公司已经在仓库执行配置表中已经设置为1)
     * parameter currentWareCode ,selectCode 
     *  更改wuyang
     * **/
    public ArrayList queryWareHouseAndStorageConfig(String currentWareCode,String selectCode) throws GSException{
        ArrayList wareList = dao.queryWareHouseAndStorageConfig(currentWareCode);
        ArrayList WareHouseList = new ArrayList();
        for (int tI = 0; tI < wareList.size(); tI++) {
            GSWareHouseBean tGSWareHouseBean=(GSWareHouseBean) wareList.get(tI);
            ArrayList warechildList = dao.queryWareHouse( tGSWareHouseBean.getCode());
            for (int i = 0; i < warechildList.size(); i++) {
            	 GSWareHouseBean tGSWareHouseChildBean=(GSWareHouseBean) warechildList.get(i);
            	 tGSWareHouseChildBean.setName(getWarehouseName(selectCode, tGSWareHouseChildBean.getCode(), tGSWareHouseChildBean.getName()+"("+tGSWareHouseChildBean.getCode()+")"));
            	 WareHouseList.add(tGSWareHouseChildBean);
			}
           
        }
        return WareHouseList;
    }
    
    /**
     * 对仓库名称按级别显示
     * (订货单位只显示分公司)
     *  更改wuyang
     * **/
    public ArrayList queryCompany(String currentWareCode,String selectCode) throws GSException{
    	 ArrayList wareList = dao.queryCompany(currentWareCode);
         for (int tI = 0; tI < wareList.size(); tI++) {
             GSWareHouseBean tGSWareHouseBean=(GSWareHouseBean) wareList.get(tI);
             tGSWareHouseBean.setName(getWarehouseName(selectCode, tGSWareHouseBean.getCode(), tGSWareHouseBean.getName()+"("+tGSWareHouseBean.getCode()+")"));
         }
         return wareList;
    }
    
    
    
    /** 设计出 具有等级标志的 仓库名称列表*/
    private static String getWarehouseName(String currentTopCode,String currentCode,String currentName){
        int level = calculateWarehouseCode(currentTopCode, currentCode);
        String warehouseName = loopWarehouseName(level, currentName);
        return warehouseName;
    }
    
    /** 计算  仓库编码    级别*/
    private static int calculateWarehouseCode(String currentTopCode,String currentCode){
        int topLen = currentTopCode.length();
        int currentLen = currentCode.length();
        int level = currentLen - topLen;
        level = level/2;
        return level;
    }
    
    /** 循环 根据仓库编码级别 形成带特殊符号的仓库名称*/
    private static String loopWarehouseName(int level,String warehouseName){
        String label = "";
        for (int i = 0; i < level; i++) {
            label += "--";
        }
        label += warehouseName;
        return label;
    }
    
    public String getWarehouseName(String code){
        return dao.getWarehouseName(code);
    }
}
